<?php
class CategoryAction extends CommonAction{

	public function index(){
		if(!isset($_GET["id"])){
			$allCategories = $this->getAllCategories();
			$this->assign("allCategories",$allCategories);
		}else{
			$categories = $this->Categories();
			if(!empty($categories)){
				$this->assign("allCategories",$categories());
			}else{
				
				$allCategories = $this->getAllCategories();
				$this->assign("allCategories",$allCategories);
			}
		}

		$this->display();
	}

	protected function Categories(){
		$parentId = $_GET["id"];
		$CategoryModel = D("Category");
		
		if(isset($_GET["id"])){
			$condition['parent'] = array('eq',$_GET["id"]);
		}else if(isset($_GET["subCategory"])){
			$condition['id'] = array('eq',$_GET["subCategory"]);
		}
		
		$Categories = $CategoryModel->where("parent=" . $parentId)->order("category_name asc ")->select();
		return $Categories;
	}

}
?>